import express from "express";
import {
  addOrderItems,
  getOrderById,
  getOrders,
  updateOrderToPaid,
  getMyOrders,
  updateOrderToDelivered,
} from "../controller/orderController.js";
import { admin, protect } from "../middleware/auth.js";
const router = express.Router();

//提交订单
//获取所有订单
router.route("/").post(protect, addOrderItems).get(protect, admin, getOrders);

//获取当前用户所有订单
router.route("/myorders").get(protect, getMyOrders);

//根据id获取订单
router.route("/:id").get(protect, getOrderById);

//更新订单支付状态
router.route("/:id/pay").put(protect, updateOrderToPaid);

//更新订单发货状态
router.route("/:id/deliver").put(protect, admin, updateOrderToDelivered);

export default router;
